﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SchoolCardSystem
{
    public partial class selectPrice : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //定义数据库信息
            MySqlConnection connection = new MySqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["connection"].ConnectionString.ToString());
            //打开数据库
            connection.Open();
            String userId = Session["name"].ToString();

            string sqlstr = @"select cardPrice from card where cardId=@userId";
            //Command 查询语句
            MySqlCommand cmd = new MySqlCommand(sqlstr, connection);
            //设置@userId的类型
            cmd.Parameters.Add(new MySqlParameter("@userId", MySqlDbType.VarChar, 11));
            cmd.Parameters["@userId"].Value = userId;

            //在线模式
            MySqlDataReader dr = cmd.ExecuteReader();
            //查询失败
            if (!dr.Read())
            {
                error.Style["display"] = "inline";
            }
            //查询成功
            else {
                money.Text = dr["cardPrice"].ToString();
            }
            connection.Close();
        }
    }
}